package com.yiwyn;

import lombok.Data;

import java.util.Arrays;
import java.util.List;

public class ExampleMain {

    public static void main(String[] args) {
        Niuma niu = new Niuma();
        niu.setName("牛桑");
        niu.setFirstThingAtWork(new FirstThingAtWork() {
            @Override
            public void doWork(String name) {
                System.out.println(name + "先去厕所摸鱼");
            }
        });

        Niuma ma = new Niuma();
        ma.setName("马桑");
        ma.setFirstThingAtWork(name -> {
            System.out.println(name + "先吃饭");
        });
        // 今天上班的人
        List<Niuma> list = Arrays.asList(niu, ma);
        // 到点了
        for (Niuma niuma : list) {
            niuma.doFirstWork();
        }
    }

    @Data
    public static class Niuma {
        // 名字
        private String name;
        // 第一件事
        private FirstThingAtWork firstThingAtWork;
        /**
         * 第一件事
         */
        public void doFirstWork() {
            firstThingAtWork.doWork(name);
        }
    }

    @FunctionalInterface
    interface FirstThingAtWork {
        void doWork(String name);
    }

}
